﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using Kaesoft.Hospedaje.Entities;

namespace Kaesoft.Hospedaje.Admin.UserControls
{
    public partial class ArbolPerfil : UserControl
    {
        ArbolPerfilViewModel viewmodel;
        List<RadTreeViewItem> items = new List<RadTreeViewItem>();
        
        public ArbolPerfil()
        {
            InitializeComponent();
           Loaded += ArbolPerfil_Loaded;
        }

        void ArbolPerfil_Loaded(object sender, RoutedEventArgs e)
        {
            if (DataContext is ArbolPerfilViewModel)
            {
                viewmodel = (ArbolPerfilViewModel)DataContext;
                viewmodel.ItemCargado += (senderCargado, ev) =>
                {

                    var itemSeleccionado = viewmodel.NodoSeleccionado;
                    rtvGruposTipos.ExpandAll();
                    var listaItems = rtvGruposTipos.Items.First() as Arbol;

                    if (listaItems.ArbolHijo != null)
                    if (listaItems.ArbolHijo.Count > 0)
                        rtvGruposTipos.SelectedItem = itemSeleccionado != null ? listaItems.ArbolHijo.Where(item => item == itemSeleccionado).FirstOrDefault() : rtvGruposTipos.Items.First();

                    
                };
            }
        }
    }
}
